<template>
  <div>
    <div class="top">
      <van-icon class="zuo" name="arrow-left" />
      分类
    </div>
    <div class="main">
      <van-sidebar v-model="activeKey" @change="onChange" class="left">
        <van-sidebar-item :title="i" v-for="i in list" :key="i">
        </van-sidebar-item>
      </van-sidebar>
      <van-grid column-num="1">
        <van-grid-item
          icon="photo-o"
          :text="item.brand"
          v-for="item in goodslist"
          :key="item.id"
          @click="gotext(item.brand)"
        />
      </van-grid>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Footer from "@/components/Footer.vue";
import { getList, getgoods } from "@/api/list";
export default {
  components: {
    Footer,
  },
  created() {
    // console.log(this.$refs.name);
    getList({
      url: "pro/categorylist",
    }).then((res) => {
      this.list = res.data.data;
      console.log(this.list);
    });

    getgoods({ category: "手机" }).then((res) => {
      // console.log(res.data);
      this.goodslist = res.data.data;
      console.log(this.goodslist);
    });
  },
  data() {
    return {
      activeKey: 0,
      list: [],
      goodslist: [],
    };
  },
  methods: {
    onChange(index) {
      console.log(this.list[index]);
      localStorage.setItem("category", this.list[index]);
      getgoods({ category: this.list[index] }).then((res) => {
        // console.log(res.data);
        this.goodslist = res.data.data;
        console.log(this.goodslist);
      });
    },
    gotext(name) {
      // console.log(this.list[index]);
      console.log(name);
      this.$router.push("/Searchgoods/" + name);
    },
  },
};
</script>

<style scoped>
.top {
  width: 100%;
  height: 3.125rem;
  font-size: 1.25rem;
  text-align: center;
  line-height: 3.125rem;
  background-color: red;
  position: relative;
}
.zuo {
  position: absolute;
  left: 0.625rem;
  font-size: 1.25rem;
  top: 0.9375rem;
}
.main {
  display: flex;
}
.van-grid {
  width: 6.25rem;
  height: 6.25rem;
}
</style>